<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>团队详情</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
    <style type="text/css">
			table th{
				text-align: center;
	            white-space: nowrap;
	        }
			table td{
				text-align: center;
	            white-space: nowrap;
	        }
		    table{
		         empty-cells:show; 
		         border-collapse: collapse;
		         margin:0 auto;
		    }
 		
			.pcc{
				width: 110px;
				height: 34px;
				text-align: center;
				border-color:#ccc;
			}
			input{
				text-indent:10px;
				width: 80%;
				border-radius:5px;
			}
			.search-btnn {
			    float: left;
			     width: 80px; 
			    margin-left: 5px;
			}
		</style>
</head>
<body>
<div id="wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header">团队详情</h1>
		</div>
	</div>

			<label class="search-label">会员手机号：</label><input type="text" id="sPhone" value="" placeholder="手机号" class="form-control search-input width200" maxlength="21">
			<label class="search-label">会员卡号：</label><input type="text" id="sCard" value="" placeholder="请输入会员卡号" class="form-control search-input width200" maxlength="21">
		    <label class="search-label">公司：</label>
		    <div class="search-input">
	        	<select name="sSeller" id="sSeller" class="form-control" >
	        		<c:if test="${fn:length(sellerList) > 0}">
	        			<option value="">请选择公司</option>
	        			<c:forEach items="${sellerList}" var="seller" varStatus="s">
								<option value="${seller.sellerId }">${seller.sellerName }</option>	
						</c:forEach>
	        		</c:if>
	        	</select>
	        </div>
		    <label class="search-label">分公司：</label>
		    <div class="search-input">
	        	<select name="sStore" id="sStore" class="form-control" >
	        			<option value="">请选择分公司</option>
	        	</select>
	        </div>
		    <label class="search-label">营业部：</label>
		    <div class="search-input">
			    <select name="sDao" id="sDao" class="form-control" >
		        	<option value="">请选择营业部</option>
		        </select>
		    </div>
			<div class="title-top col-lg-12">
				 <!-- <label class="search-label">办卡日期：</label><input type="text" id="beginDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				 <label class="search-label">至</label><input type="text" id="endDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" > -->
				<label class="search-label">会员生日：</label><input type="text" id="sBeginDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">至</label><input type="text" id="sEndDate" value="" placeholder="年-月-日" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				 <label class="search-label">会员状态：</label>
				<div class="search-input">
					<select id="sState" class="selectpicker" multiple="multiple" data-width="150">
						<option value="1">未登录</option>
						<option value="2">未注册</option>
						<option value="3">会员</option>
					</select>
				</div>
		<div class="search-input">
		<label class="search-label">等级：</label>
			<select id="sTaici" class="selectpicker" multiple="multiple" data-width="150">
				<option value="1">会员</option>
				<option value="2">黄金</option>
				<option value="3">白金</option>
				<option value="4">经纪人</option>
				<option value="5">营业部</option>
				<option value="6">分公司</option>
			</select>
			</div>
			<button class="btn btn-success search-btn" onclick="query();">确定</button>
			<button class="btn btn-success search-btn" onclick="reset();">重置</button>
			<%-- <button class="btn btn-success search-btnn" onclick="sendTemplate();">模板推送</button>
			<shiro:hasPermission name="bus:user:sendMessage">
			<button class="btn btn-success search-btnn" onclick="sendMessage();">选择推送</button>
			<button class="btn btn-success search-btnn" onclick="sendAllMessage();">全部推送</button>
			</shiro:hasPermission> --%>
			<div class="clearfix"></div>
		
	<div class="row" >
		<div class="col-lg-12">
			<div class="row">
				<div>
					<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
					<c:if test="${session.userpopedom.busUserDoExcel==1}">
					<button onclick="doExcel();" class="btn btn-success" style="float:right;margin-right: 30px;margin-bottom:10px;">导出</button>
					</c:if>
				</div>
			</div>
			<div class="table-responsive panel panel-default" >
				<table id="dataTable" class="table table-hover table-bordered" style="overflow:scroll;">
		            <thead>
		               	<tr>
		               		<th width="50px;"></th>
							<th width="150px;">会员卡号</th>
							<th width="80px;">会员姓名</th>
							<th width="120px;">会员手机号</th>
							<th width="210px;">所属公司</th>
							<th width="120px;">所属分公司</th>
							<th width="80px;">营业部</th>
							<th width="100px;">团队人数</th>
							<th width="80px;">邀请人</th>
							<th width="100px;">办卡日期</th>
							<th width="100px;">会员生日</th>
							<th width="100px;">会员状态</th>
							<th width="80px;">等级</th>
							<th width="100px;">升级日期</th>
							<th width="100px;">消费次数</th>
						</tr>
		            </thead>
		            <tbody id="dataList"></tbody>
		        </table>
			</div>
	        <div class="row">
	        	<div class="col-lg-12">
	        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
	        	</div>
	        </div>
		</div>
	</div>
</div>
</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
		{{each list as item}}
				 <tr id="item{{item.id}}" data-id="{{item.id}}">
					<td><input type="checkbox" name="check_name" value="{{item.phone}}" style="height:20px;"></td>
				 	<td>
						<a href="javascript:showUser('{{item.id}}');">
							<font color="#40a9ff" id="dataCount">
								{{if item.card}}{{item.card }}{{/if}}
								{{if !item.card}}--{{/if}}
							</font>
						</a>
					</td>
					<td>{{item.name}}</td>
					<td>{{item.phone}}</td>
					<td>
						{{if item.sellerName}}{{item.sellerName }}{{/if}}
						{{if !item.sellerName}}--{{/if}}
					</td>
                    <td>
						{{if item.storeName}}{{item.storeName }}{{/if}}
						{{if !item.storeName}}--{{/if}}
					</td>
					<td>
						{{if item.toBossOneId}}{{item.trueName}}{{/if}}
						{{if !item.toBossOneId}}--{{/if}}
					</td>
					<td>
						{{if item.userNum}}<a href="javascript:showTeam('{{item.id}}');"><font color="#40a9ff" id="dataCount">{{item.userNum}}</font></a>{{/if}}
						{{if !item.userNum}}0{{/if}}
						
					</td>
					<td>
						{{if item.pareName}}<a href="javascript:showUser('{{item.inviteid}}');"><font color="#40a9ff" id="dataCount">{{item.pareName}}</font></a>{{/if}}
						{{if !item.pareName}}--{{/if}}
					</td>
					<td>{{item.createDate}}</td>
					<td>
						{{if item.birthday}}{{item.birthday}}{{/if}}
						{{if !item.birthday}}--{{/if}}
					</td>
					<td>{{item.state | flagTransform:1,'未登录',2,'未注册',3,'会员'}}</td>
					<td>{{item.taici | flagTransform:1,'会员',2,'黄金',3,'白金',4,'经纪人',5,'营业部',6,'分公司'}}</td>
					<td>
							{{if item.babythday}}{{item.babythday }}{{/if}}
							{{if !item.babythday}}--{{/if}}
					</td>
					<td style="color: #33a6dc;" onclick="convert({{item.id}},{{item.countnum}})">{{item.countnum}}</td>
				</tr>
		{{/each}}
</script>
<script src="${BASE_PATH}/static/js/PCASClass.js" type="text/javascript"></script>
<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	var phone=$("#sPhone").val(),card=$("#sCard").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
	 seller=$("#sSeller").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val();
	 var id=${id};
// 	 var province=$("#Sprovince").val(),city=$("#Scity").val(),area=$("#Sarea").val();
	 //地址筛选拼接
// 	 var address=province+city+area;
	 var taicis="",states="";
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
		var params = {
				id:id,
				pageSize:10,
				phone:phone,
				card:card,
				sBeginDate:sBeginDate,
				sEndDate:sEndDate,

//		 		address:address,
				seller:seller,
				store:store,
				dao:dao,
				taici:taicis,
				state:states};
		if(dataPaginator){
			dataPaginator.destroy();
		}
		dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/bus/user/teampage",params,function(result){
			//设置显示最新的数据数量
			$("#dataCount").html(result.object.totalRow);
			//根据模板渲染数据并填充
			$("#dataList").empty().append(template("dataTpl",result.object));
		});
}
var messageDialog;
function sendMessage(){
	var adIds = "";  
    $("input:checkbox[name=check_name]:checked").each(function(i){  
        if(0==i){  
            adIds = $(this).val();  
        }else{  
            adIds += (","+$(this).val());  
        }  
    }); 
    if(adIds==""){
    	Kit.alert("请选择要发送信息的人员");
    }else{
  		 messageDialog=Kit.dialog("消息推送","${BASE_PATH}/bus/user/sendMessage/"+adIds,{size:'size-wide',closable:true}).open();
    }
}
function sendTemplate(){
	var dataCount=$("#dataCount").html();
	if(parseInt(dataCount)>300){
		Kit.alert("模板消息最多推送300个用户");
	}else{
		 var phone=$("#sPhone").val(),card=$("#sCard").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
		 var beginDate=$("#beginDate").val(),endDate=$("#endDate").val(),store=$("#sStore").val(),dao=$("#sDao").val();
		 var taici=$("#sTaici").val(),state=$("#sState").val();
		 var taicis="",states="";
			if(taici !=null && taici !="" && taici !=undefined){
				taicis=taici.join("','");
			}
			if(state !=null && state !="" && state !=undefined){
				states=state.join("','");
			}
		 messageDialog=Kit.dialog("消息推送","${BASE_PATH}/bus/user/sendTemplate?phone="+phone+"&beginDate="+beginDate+"&endDate="
				+endDate+"&card="+card+"&sBeginDate="+sBeginDate+"&sEndDate="+sEndDate+"&store="+store+"&dao="
				+dao+"&taici="+taicis+"&state="+states,{size:'size-wide',closable:true}).open();
	}
}
function sendAllMessage(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
	 var beginDate=$("#beginDate").val(),endDate=$("#endDate").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val();
	 var taicis="",states="";
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
	 messageDialog=Kit.dialog("消息推送","${BASE_PATH}/bus/user/message?phone="+phone+"&beginDate="+beginDate+"&endDate="
			+endDate+"&card="+card+"&sBeginDate="+sBeginDate+"&sEndDate="+sEndDate+"&store="+store+"&dao="
			+dao+"&taici="+taicis+"&state="+states,{size:'size-wide',closable:true}).open();
}
function reset(){
	$("#sPhone").val("");$("#sCard").val("");
	$("#sBeginDate").val("");$("#sEndDate").val("");
	$("#sSeller").val("");$("#sSeller").trigger("change");
	$("#sStore").val("");$("#sStore").trigger("change");
	$("#sDao").val("");$("#sDao").trigger("change");
	$("#sTaici").val("");$("#sTaici").trigger("change");
	$("#sState").val("");$("#sState").trigger("change");
	$("#sStore").selectpicker("refresh"); $("#sDao").selectpicker("refresh");$("#sState").selectpicker("refresh"); $("#sTaici").selectpicker("refresh");
}

var showDialog;
function showUser(id){
	showDialog = Kit.dialog("会员详情信息","${BASE_PATH}/bus/user/detail/"+id,{size:'size-wide',closable:true}).open();
}
function showTeam(id){
	window.location.href="${BASE_PATH}/bus/user/showTeam?id="+id;
}
function onEditSuccess(newObject){
	$("#item"+newObject.id).replaceWith(template("dataTpl",{"list":[newObject]}));
}

function convert(id,n){
	if(!n){
		return Kit.alert("此会员兑换次数为零");
	}
		location.href="${BASE_PATH}/bus/order/convert?userId="+id;   	
}  
$("#sStore").change(function(){
	sStore=$("#sStore").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/bus/user/chooseDao",
           data: {"store" : sStore},
           dataType: "json",
           traditional: true,
           success: function(data){
          	   $("#sDao").empty(); 
               $("#sDao").append("<option value=''>请选择营业部</option>");
               for(var i=0; i<data.object.length;i++){
              	 $("#sDao").append("<option value='"+data.object[i].trueName+"'>"+data.object[i].trueName+"</option>");
               }
              	//$("#sDao").selectpicker("refresh");
           }
       });
    });
//异步取分公司的值
$("#sSeller").change(function(){
	sSeller=$("#sSeller").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/bus/user/chooseStore",
           data: {"seller" : sSeller},
           dataType: "json",
           traditional: true,
           success: function(data){
			$("#sStore").empty(); 
			$("#sStore").append("<option value=''>请选择分公司</option>");
			for(var i=0; i<data.object.length;i++){
				$("#sStore").append("<option value='"+data.object[i].storeid+"'>"+data.object[i].title+"</option>");
               }
              // $("#toBossOneId").selectpicker("refresh");	
           }
       });
    });
</script>
</body>
</html>